package cn.trip.controller;

import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONArray;

import cn.trip.pojo.Trip_bill;
import cn.trip.pojo.Trip_product;
import cn.trip.pojo.Trip_provider;
import cn.trip.pojo.Trip_room;
import cn.trip.service.provider.ProviderService;
import cn.trip.utils.Constants;
import cn.trip.utils.PageSupport;

@Controller
@RequestMapping("/provider")
public class ProviderController {

	private Logger logger = Logger.getLogger(ProviderController.class);
	@Resource(name = "providerService")
	private ProviderService service;

	// 跳转到登陆页面
	@RequestMapping("/login")
	public String dologin() {
		return "provider/login";
	}

	// 登陆
	@RequestMapping("/dologin.html")
	public String logining(@RequestParam String proCode, @RequestParam String password, HttpSession session) {

		Trip_provider provider = service.login(proCode, password);
		if (provider != null) {
			session.setAttribute(Constants.PROVIDER_SESSION, provider);
			return "redirect:/provider/main.html";
		} else {
			return "provider/login";
		}

	}

	// 会话过期，重新登陆
	@RequestMapping(value = "/main.html")
	public String main(HttpSession session) {
		if (session.getAttribute(Constants.PROVIDER_SESSION) == null) {
			return "redirect:/provider/login";
		}
		return "provider/providerIndex";
	}

	// 退出登录
	@RequestMapping(value = "loginout.html")
	public String loginOut(HttpSession session) {
		session.setMaxInactiveInterval(20);
		return "redirect:/index/index.do";

	}

	// 注册页面
	@RequestMapping("/sign.html")
	public String signUp(Model model) {
		// 生成编号
		Random random = new Random();
		String proCode="";
		for (int i=0;i<6;i++)
		{
			proCode+=random.nextInt(10);
		}
		model.addAttribute("proCode", proCode);
		return "/provider/signup";
	}
	// 商家注册保存
	@RequestMapping("signsave.html")
	public String signSave(@RequestParam(value="proCode",required=false) String proCode,
	@RequestParam(value="proName",required=false) String proName,
	@RequestParam(value="proAddress",required=false)String proAddress,
	@RequestParam(value="proPhone",required=false) String proPhone,
	@RequestParam(value="newpassword",required=false)String password,
	@RequestParam(value = "attach", required = false) MultipartFile attach,
	HttpServletRequest request){
		String org_PicPath = null;
		if (!attach.isEmpty()) {
			// 定义目标上次路径
			String path = "D:/pic";
			// 源文件文件名
			String oldFileName = attach.getOriginalFilename();
			// 源文件后缀
			String prefix = FilenameUtils.getExtension(oldFileName);
			int filesize = 5000000;
			if (attach.getSize() > filesize) {
				request.setAttribute("error", "上传大小不得超过5000K");
				return "/provider/sign.html";
			} else if (prefix.equalsIgnoreCase("jpg")
					|| prefix.equalsIgnoreCase("png")
					|| prefix.equalsIgnoreCase("pneg")
					|| prefix.equalsIgnoreCase("jpeg")) {
				// 当前系统时间+随机数+"org_PicPath.jpg"
				String fileName = System.currentTimeMillis()
						+ RandomUtils.nextInt(1000000) + "org_PicPath.jpg";

				File targetFile = new File(path, fileName);
				if (!targetFile.exists()) {
					// 创建文件
					targetFile.mkdirs();
				}
				try {
					// 文件流输出到文件中
					attach.transferTo(targetFile);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					request.setAttribute("error", "上传失败");
					return "provider/sign.html";
				}
				org_PicPath = fileName;
			} else {
				request.setAttribute("error", "图片格式不正确");
				return "provider/sign.html";
			}
		}


		if (proCode != null 
				&& password.length() == 6 && org_PicPath != null) {
			Trip_provider provider = new Trip_provider();
			provider.setProCode(proCode);
			provider.setProName(proName);
			provider.setPassword(password);
			provider.setProPhone(proPhone);
			provider.setProAddress(proAddress);
			provider.setOrg_PicPath(org_PicPath);
			Date date = new Date();
			provider.setCreateDate(date);
			if (service.dosign(provider)>0) {//插入数据
				request.setAttribute("message", "注册成功，请重新登陆！");
				return "provider/login";
			}
			
		}
		return "provider/sign.html";
	}

	// 商品信息表
	@RequestMapping("/productList")
	public String proList(@RequestParam(value = "proCode", required = false) String proCode,
			@RequestParam(value = "queryName", required = false) String queryName,
			@RequestParam(value = "pageIndex", required = false) Integer pageIndex, HttpSession session, Model model) {
		logger.info("当前用户=============================》" + proCode);
		List<Trip_product> proList = null;
		// 设置页面容量
		int pageSize = Constants.pageSize;
		// 当前页码
		int currentPageNo = 1;

		if (proCode == null) {
			proCode = "";
		}

		if (pageIndex != null) {
			try {
				currentPageNo = Integer.valueOf(pageIndex);
			} catch (NumberFormatException e) {
				return "redirect:/user/syserror.html";
				// response.sendRedirect("syserror.jsp");
			}
		}

		// 总数量（表）
		int totalCount = service.proCount(proCode, queryName);
		// 总页数
		PageSupport pages = new PageSupport();
		pages.setCurrentPageNo(currentPageNo);
		pages.setPageSize(pageSize);
		pages.setTotalCount(totalCount);
		int totalPageCount = pages.getTotalPageCount();

		// 控制首页和尾页
		if (currentPageNo < 1) {
			currentPageNo = 1;
		} else if (currentPageNo > totalPageCount) {
			currentPageNo = totalPageCount;
		}

		proList = service.productlist(proCode, queryName, currentPageNo, pageSize);
		model.addAttribute("list", proList);
		logger.info("===========================>集合长度" + proList.size());
		model.addAttribute("proCode", proCode);
		/* model.addAttribute("proName", proName); */
		model.addAttribute("totalPageCount", totalPageCount);
		model.addAttribute("totalCount", totalCount);
		model.addAttribute("currentPageNo", currentPageNo);
		return "provider/productList";
	}

	// 查看商品信息，使用rest风格
	@RequestMapping(value = "/{id}/view")
	public String view(@PathVariable String id, Model model) {
		logger.info("===================>商品id" + id);
		Trip_product product = service.getProduct(id);
		model.addAttribute("product", product);

		return "provider/product";

	}

	// 查看酒店的房型信息
	@RequestMapping("/roomlist")
	public String getRoomList(@RequestParam(value = "hotelName") String hotelName, Model model) {
		logger.info(hotelName);
		List<Trip_room> rooms = service.roomList(hotelName);
		model.addAttribute("roomlist", rooms);
		return "/provider/roomMessage";
	}

	// 删除商品
	@ResponseBody
	@RequestMapping(value = "/prodelete")
	public Object delpro(@RequestParam("proid") String id) {
		logger.info("商品id=================>" + id);
		Map<String, String> results = new HashMap<String, String>();
		if (service.getProduct(id).getStatus() == 0) {
			if (service.getProduct(id).getP_type() == 2) {// 如果是酒店，还要删除对应的房型信息表
				if (service.delroomList(service.getProduct(id).getP_Name()) > 0) {
					if (service.getdel(id)) {
						results.put("delResult", "true");
					} else {
						results.put("delResult", "false");
					}

				} else {
					results.put("delResult", "false");
				}
			} else {
				if (service.getdel(id)) {
					results.put("delResult", "true");
				} else {
					results.put("delResult", "false");
				}
			}

		} else {
			results.put("delResult", "商品正在上架，无法进行删除处理！");
		}

		return results;
	}

	// 跳转增加商品页面
	@RequestMapping("addproduct")
	public String addpro(Model model, Trip_product product) {
		model.addAttribute("product", product);
		return "/provider/addProduct";
	}

	// 跳转增加酒店房型页面
	@RequestMapping("/hotel")
	public String addhotel(@RequestParam("hotelName") String hotelName, Model model) {
		logger.info("=========》成功进入房型页面,打印酒店名字" + hotelName);
		model.addAttribute("hotelName", hotelName);
		return "/provider/room";
	}

	// 保存酒店房型信息
	@RequestMapping("/roomsave")
	public String saveRoom(@RequestParam(value = "roomName") String[] roomNames,
			@RequestParam(value = "rest") Integer[] rests, @RequestParam(value = "roomPrice") Double[] roomPrices,
			@RequestParam(value = "roomDesc") String[] roomDescs, @RequestParam(value = "hotelName") String hotelName,
			HttpServletRequest request, HttpSession session,
			@RequestParam(value = "attachs", required = false) MultipartFile[] attachs) {
		logger.info("=========》成功酒店保存方法，打印房型名字的长度：" + rests.length);
		String Pic_Path = null; // 文件传输的路径
		boolean flag = true; // 表示是否传输成功
		String errorInfo = null;
		// 1.编写指定目标路径
		String path = "D:/pic";
		logger.info("文件传输的数组长度================》" + attachs.length);
		for (int i = 0; i < attachs.length; i++) {
			MultipartFile attach = attachs[i];
			// 进行文件上传1.文件是否为空
			if (!attach.isEmpty()) {// 不为空,定义上传目标路径
				if (i == 0) {
					errorInfo = "uploadFileError";
				} else if (i == 1) {
					errorInfo = "uploadWpError";
				}
				// 定义上传目标路径
				String oldFileNameString = attach.getOriginalFilename();
				String prefix = FilenameUtils.getExtension(oldFileNameString);// 获得原文件的后缀
				// 2.判断文件大小
				int filesize = 5000000;
				if (attach.getSize() > filesize) {
					request.setAttribute(errorInfo, "*上传大小不能大于5000k");
					flag = false;
				} else if (prefix.equalsIgnoreCase("jpg") || prefix.equalsIgnoreCase("jpeg")
						|| prefix.equalsIgnoreCase("png") || prefix.equalsIgnoreCase("pneg")) {
					// 当前系统时间+随机数+"_Personal.jpg"
					String fileNameString = System.currentTimeMillis() + RandomUtils.nextInt(1000000) + "_Room.png";
					File targetFile = new File(path, fileNameString);
					if (!targetFile.exists()) {
						targetFile.mkdirs();
					}
					try {
						attach.transferTo(targetFile);
					} catch (Exception e) {
						e.printStackTrace();
						request.setAttribute(errorInfo, "*上传失败");
						flag = false;
					}
					if (i == 0) {
						Pic_Path = fileNameString;
						logger.info("Pic_Path========>" + Pic_Path);
					} else if (i == 1) {
						Pic_Path = fileNameString;
					}

				} else {
					request.setAttribute(errorInfo, "*上传图片格式不正确");
					flag = false;
				}
			}
			Trip_room room = new Trip_room();
			room.setHotelName(hotelName);
			room.setPic_Path(Pic_Path);
			room.setRest(rests[i]);
			room.setRoomDesc(roomDescs[i]);
			room.setRoomName(roomNames[i]);
			room.setRoomPrice(roomPrices[i]);
			room.setUsingDate(new Date());
			if(service.addRoom(room)){
				flag = true;
			}
		}

		if (flag) {
			Trip_provider provider = ((Trip_provider) session.getAttribute(Constants.PROVIDER_SESSION));
			if (provider != null) {
				return "redirect:/provider/productList?proCode=" + provider.getProCode();
			} else {
				return "redirect:/provider/main.html";
			}

		} else {
			return "redirect:/provider/hotel?hotelName=" + hotelName;
		}
	}

	// 保存商品
	@RequestMapping("addsave")
	public String addsave(Trip_product product, HttpSession session, HttpServletRequest request,
			@RequestParam(value = "attachs", required = false) MultipartFile[] attachs, Model model) {
		// 上传文件
		String errorInfo = null; // 错误提示信息
		String org_PicPath = null; // 文件传输的路径
		String Pic_Path_1 = null; // 文件传输的路径
		String Pic_Path_2 = null; // 文件传输的路径
		String Pic_Path_3 = null; // 文件传输的路径
		boolean flag = true; // 表示是否传输成功
		// 1.编写指定目标路径
		String path = "D:/pic";
		logger.info("文件传输的数组长度================》" + attachs.length);
		for (int i = 0; i < attachs.length; i++) {
			MultipartFile attach = attachs[i];
			// 进行文件上传1.文件是否为空
			if (!attach.isEmpty()) {// 不为空,定义上传目标路径
				if (i == 0) {
					errorInfo = "uploadFileError";
				} else if (i == 1) {
					errorInfo = "uploadWpError";
				}
				// 定义上传目标路径
				String oldFileNameString = attach.getOriginalFilename();
				String prefix = FilenameUtils.getExtension(oldFileNameString);// 获得原文件的后缀
				// 2.判断文件大小
				int filesize = 5000000;
				if (attach.getSize() > filesize) {
					request.setAttribute(errorInfo, "*上传大小不能大于5000k");
					flag = false;
				} else if (prefix.equalsIgnoreCase("jpg") || prefix.equalsIgnoreCase("jpeg")
						|| prefix.equalsIgnoreCase("png") || prefix.equalsIgnoreCase("pneg")) {
					// 当前系统时间+随机数+"_Personal.jpg"
					String fileNameString = System.currentTimeMillis() + RandomUtils.nextInt(1000000) + "_Personal.jpg";
					File targetFile = new File(path, fileNameString);
					if (!targetFile.exists()) {
						targetFile.mkdirs();
					}
					try {
						attach.transferTo(targetFile);
					} catch (Exception e) {
						e.printStackTrace();
						request.setAttribute(errorInfo, "*上传失败");
						flag = false;
					}
					if (i == 0) {
						org_PicPath = fileNameString;
						logger.info("org_PicPath========>" + org_PicPath);
					} else if (i == 1) {
						Pic_Path_1 = fileNameString;
						logger.info("Pic_Path_1========>" + Pic_Path_1);
					} else if (i == 2) {
						Pic_Path_2 = fileNameString;
						logger.info("Pic_Path_2========>" + Pic_Path_2);
					} else if (i == 3) {
						Pic_Path_3 = fileNameString;
						logger.info("Pic_Path_3========>" + Pic_Path_3);
					}

				} else {
					request.setAttribute(errorInfo, "*上传图片格式不正确");
					flag = false;
				}
			}
		}

		if (flag) {
			// 当前的用户信息 session
			Trip_provider provider = ((Trip_provider) session.getAttribute(Constants.PROVIDER_SESSION));
			product.setCreateBy(provider.getProCode());
			product.setCreateDate(new Date());
			product.setStatus(1);
			product.setOrg_PicPath(org_PicPath);
			product.setPic_Path_1(Pic_Path_1);
			product.setPic_Path_2(Pic_Path_2);
			product.setPic_Path_3(Pic_Path_3);

			if (service.addpro(product)) {
				if (product.getP_type() == 2) {
					logger.info("酒店名字===========>" + product.getP_Name());
					model.addAttribute("hotelName", product.getP_Name());
					return "redirect:/provider/hotel";// 如果是酒店的话，进入到酒店房型保存
				}

				return "redirect:/provider/productList?proCode=" + provider.getProCode();
			}
		}
		return "/provider/addproduct";
	}

	// 验证商品是否已经存在
	@RequestMapping("isExist")
	@ResponseBody
	public String proIsExist(@RequestParam(value = "pname", required = false) String productName,
			@RequestParam(value = "address", required = false) String address, HttpSession session) {
		// 当前的用户信息 session
		Trip_provider provider = ((Trip_provider) session.getAttribute(Constants.PROVIDER_SESSION));
		String proCode = provider.getProCode();
		String result = null;
		if (!service.getproductByName(proCode, productName, address)) {
			result = "noexist";
		} else {
			result = "exist";
		}
		return JSONArray.toJSONString(result);
	}

	// 跳转到修改信息页面
	@RequestMapping("/modify")
	public String modify(Model model, @RequestParam(value = "proid", required = false) String id) {
		logger.info("id============================>" + id);
		Trip_product product = service.getProduct(id);
		model.addAttribute("product", product);
		return "/provider/modifyProduct";
	}

	// 保存修改的商品信息
	@RequestMapping("/modifysave")
	public String modifysave(Trip_product product) {
		logger.info("修改商品的信息===============》id" + product.getId());
		product.setModifyDate(new Date());
		if (service.modifyproduct(product)) {// 修改成功
			return "redirect:/provider/productList?proCode=" + product.getCreateBy();
		} else {
			return "/provider/modifyProduct";
		}
	}

	// 跳转到修改信息页面
	@RequestMapping("/modifyRoom")
	public String modifyRoom(Model model, @RequestParam(value = "room_id", required = false) String room_id) {
		logger.info("id============================>" + room_id);
		Trip_room room = service.getRoomById(room_id);
		logger.info("酒店名字============================>" + room.getHotelName());
		model.addAttribute("room", room);
		return "/provider/modifyRoom";
	}

	// 保存修改的房型信息
	@RequestMapping("/modifyRoomsave")
	public String modifyRoomsave(Trip_room room, Model model) {
		logger.info("修改房型的信息===============》id" + room.getRoom_id());
		if (service.modifyroom(room) > 0) {// 修改成功
			model.addAttribute("hotelName", room.getHotelName());
			return "redirect:/provider/roomlist";
		} else {
			return "/provider/modifyProduct";
		}
	}

	// 删除房型信息
	@ResponseBody
	@RequestMapping(value = "/deleteRoom")
	public Object delRoom(@RequestParam("room_id") String id) {
		logger.info("房型id=================>" + id);
		Map<String, String> results = new HashMap<String, String>();
		if (service.delroom(id) > 0) {
			results.put("delResult", "true");
		} else {
			results.put("delResult", "false");
		}
		return results;
	}

	// 跳转修改商家信息
	@RequestMapping("/modifypro")
	public String modifyProvider() {
		return "/provider/modifyProvider";
	}
	
	//判断商家是否存在
	@RequestMapping("proExist")
	@ResponseBody
	public String providerExist(@RequestParam(value = "pname", required = false) String proName,
			@RequestParam(value = "address", required = false) String address, HttpSession session) {
		// 当前的用户信息 session
		String result = null;
		if (service.proName(proName, address)) {
			result = "noexist";
		} else {
			result = "exist";
		}
		return JSONArray.toJSONString(result);
	}

	// 修改商家信息
	@RequestMapping(value = "/modify.html")
	public String domodify(
			@RequestParam(value="proCode") String proCode,
			@RequestParam(value = "proName") String proName, @RequestParam(value = "proPhone") String proPhone,
			@RequestParam(value = "proAddress") String proAddress, @RequestParam(value = "proFax") String proFax,
			@RequestParam(value = "org_PicPath", required = false) MultipartFile attach, HttpServletRequest request,
			HttpSession session) {

		String org_PicPath = null;
		boolean flag = true;
		if (!attach.isEmpty()) {
			// 定义目标上次路径
			String path = "D:/pic";
			// 源文件文件名
			String oldFileName = attach.getOriginalFilename();
			// 源文件后缀
			String prefix = FilenameUtils.getExtension(oldFileName);
			int filesize = 500000;
			if (attach.getSize() > filesize) {
				request.setAttribute("error", "上传大小不得超过500K");
				flag = false;
				return "provider/modifyProvider";
			} else if (prefix.equalsIgnoreCase("jpg") || prefix.equalsIgnoreCase("png")
					|| prefix.equalsIgnoreCase("pneg") || prefix.equalsIgnoreCase("jpeg")) {
				// 当前系统时间+随机数+"org_PicPath.jpg"
				String fileName = System.currentTimeMillis() + RandomUtils.nextInt(1000000) + "org_PicPath.jpg";

				File targetFile = new File(path, fileName);
				if (!targetFile.exists()) {
					// 创建文件
					targetFile.mkdirs();
				}
				try {
					// 文件流输出到文件中
					attach.transferTo(targetFile);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					request.setAttribute("error", "上传失败");
					flag = false;
					return "provider/modifyProvider";
				}
				org_PicPath = path + File.separator + fileName;
			} else {
				request.setAttribute("error", "图片格式不正确");
				flag = false;
				return "/provider/modifyProvider";
			}
		}
		
		if (flag) {
			Trip_provider provider = new Trip_provider();
			provider.setProCode(proCode);
			provider.setProName(proName);
			provider.setProPhone(proPhone);
			provider.setProAddress(proAddress);
			provider.setProFax(proFax);
			provider.setOrg_PicPath(org_PicPath);
			provider.setModifyDate(new Date());
			if (service.modify(provider)>0){//修改商家信息成功
				logger.info("============》修改商家信息成功");
				session.setAttribute(Constants.PROVIDER_SESSION, provider);
				return "/provider/providerIndex";
			}else{
				return "provider/modifyProvider";
				
			}
		}
		
		
		return "provider/modifyProvider";
	}

	//ajax判断旧密码是否一致
	@RequestMapping("/password")
	@ResponseBody
	public String providerExist(@RequestParam(value = "oldpassword", required = false) String password,
			 HttpSession session) {
		// 当前的用户信息 session
		Trip_provider provider =(Trip_provider)session.getAttribute(Constants.PROVIDER_SESSION);
		String result = null;
		String passwordString = provider.getPassword();
		logger.info("旧密码=============》"+passwordString);
		logger.info("页面密码=============》"+password);
		if (password.equals(passwordString)) {
			result = "true";//密码输入正确
		} else {
			result = "false";
		}
		return JSONArray.toJSONString(result);
	}
	
	
	// 修改密码页面
	@RequestMapping(value = "/pwd")
	public String pwd(HttpSession session) {
		if (session.getAttribute(Constants.PROVIDER_SESSION) == null) {
			return "redirect:/provider/login";
		}
		return "provider/pwd";
	}

	// 修改密码
	@RequestMapping(value = "/modifyPwd")
	public String domodifyPwd(@RequestParam(value = "password3") String password3, HttpSession session) {

		Trip_provider provider = (Trip_provider) session.getAttribute(Constants.PROVIDER_SESSION);
		provider.setPassword(password3);
		if (service.modify(provider)>0) {
			logger.info("====================》修改密码成功");
			session.removeAttribute(Constants.PROVIDER_SESSION);
			return "provider/login";
		}
		return "provider/pwd";
	}

	//获取订单列表
	// 跳转订单展示列表页面
	@RequestMapping("/billList")
	public String getBillList(@RequestParam(value = "proCode") String proCode,
			@RequestParam(value = "pageIndex", required = false) Integer pageIndex, Model model) {
		logger.info("商家编码==========》" + proCode);
		List<Trip_bill> bills = null;
		int isPay = 1;
		// 设置页面容量
		int pageSize = Constants.pageSize;
		// 当前页码
		int currentPageNo = 1;

		if (proCode == null) {
			proCode = "";
		}

		if (pageIndex != null) {
			try {
				currentPageNo = Integer.valueOf(pageIndex);
			} catch (NumberFormatException e) {
				return "redirect:/user/syserror.html";
				// response.sendRedirect("syserror.jsp");
			}
		}

		// 总数量（表）
		int totalCount = service.billCount(proCode, isPay);
		// 总页数
		PageSupport pages = new PageSupport();
		pages.setCurrentPageNo(currentPageNo);
		pages.setPageSize(pageSize);
		pages.setTotalCount(totalCount);
		int totalPageCount = pages.getTotalPageCount();

		// 控制首页和尾页
		if (currentPageNo < 1) {
			currentPageNo = 1;
		} else if (currentPageNo > totalPageCount) {
			currentPageNo = totalPageCount;
		}

		bills = service.bills(proCode, isPay, currentPageNo, pageSize);
		model.addAttribute("list", bills);
		logger.info("===========================>订单集合长度" + bills.size());
		model.addAttribute("p_createBy", proCode);
		model.addAttribute("totalPageCount", totalPageCount);
		model.addAttribute("totalCount", totalCount);
		model.addAttribute("currentPageNo", currentPageNo);
		return "provider/BillList";
	}

	//订单处理
	// 处理订单
	@ResponseBody
	@RequestMapping(value = "/billmodify")
	public Object modifyBill(@RequestParam("b_id") String id) {
		logger.info("订单id=================>" + id);
		Trip_bill bill = service.getBillById(id);
		bill.setStatus(1);
		bill.setModifyDate(new Date());
		Map<String, String> results = new HashMap<String, String>();
		if (service.modifyBill(bill) > 0) {
			results.put("result", "true");
		} else {
			results.put("result", "false");
		}
		return results;
	}
	//订单删除

	// 删除订单信息
	@ResponseBody
	@RequestMapping(value = "/billdelete")
	public Object delBill(@RequestParam("b_id") String id) {
		logger.info("订单id=================>" + id);
		Trip_bill bill = service.getBillById(id);

		Map<String, String> results = new HashMap<String, String>();
		if (bill.getStatus() == 0) {// 订单未处理，不允许删除
			results.put("delResult", "false");
		} else {
			if (service.delBill(id) > 0) {// 删除订单
				results.put("delResult", "true");
			} else {
				results.put("delResult", "false");
			}
		}

		return results;
	}

}
